home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3148 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.2 KB

  1. Path: freenet2.freenet.ufl.edu!afn03257
  2. From: afn03257@freenet2.freenet.ufl.edu (Daniel P Hudson)
  3. Newsgroups: comp.lang.c,comp.lang.c++,alt.msdos.programmer
  4. Subject: Re: Clearing the keyboard buffer
  5. Date: 22 Jan 1996 14:45:37 GMT
  6. Message-ID: <4e07uh$oqq@huron.eel.ufl.edu>
  7. References: <4dtqi4$60u@cdc2.cdc.net>
  8. NNTP-Posting-Host: freenet2.afn.org
  9. X-Newsreader: wsOMR/SOUP v1.00 [NR]
  10.  
  11. In article <4dtqi4$60u@cdc2.cdc.net>,
  12. mart@vianet.on.ca (Mart) wrote:
  13.  
  14.  > I'm using Turbo C++ v. 3.1 and I need to be able to clear the keyboard
  15.  > BTW, this following bit of code wouldn't work :
  16.  
  17.  > while(kbhit()) getch();
  18.  
  19.  > Because I want the user to be able to just keep pushing the same key,
  20.  > making the above loop infinitly. If I don't clear the keyboard buffer, 
  21.  > my code will continue believing that the user is pushing a key, even 
  22.  > though their not.
  23.  
  24.  Huh? Once the buffer is caught up, it shouldn't continue, but you
  25.  might want to try fflush(stdin); just the same. The code you had
  26.  should work as soon as it has read through all the keystrokes currently
  27.  stored, the only way it should have a situation like you describe is if
  28.  the user presses a key after it has executed, in which case your only 
  29.  prevention would be to disable the keyboard.
  30.  
  31.